﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using Infragistics.Controls.Menus;

namespace StartupSolution.Views.Menus.BuildingMenu
{
    public partial class MenuCodeBehind : Page
    {
        private const string imageResourcePathOpen = "/StartupSolution;component/Images/MenuFileOpen.png";
        private const string imageResourcePathSave = "/StartupSolution;component/Images/MenuFileSave.png";

        public MenuCodeBehind()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(MenuCodeBehind_Loaded);
        }

        private void MenuCodeBehind_Loaded(object sender, RoutedEventArgs e)
        {

            // Create XamMenu control
            XamMenu menu = new XamMenu();

            // Set the Height, Width, Alignment properties of the XamMenu control  
            // The default orientation of the XamMenu control is horizontal.
 
            // Create a horizontal XamMenu control
            // Set the Height and Width properties of the horizontal XamMenu control
            menu.MenuOrientation = Orientation.Horizontal;
            menu.Height = 30;
            menu.Width = 400;

            // TODO: Create a vertical XamMenu control
            // If you want to display a vertical menu, uncomment the lines below.
            // Comment the horizontal menu settings - the MenuOrientation, Height and Width properties
            //
            // menu.MenuOrientation = Orientation.Vertical;
            // menu.Height = 400;
            // menu.Width = 50;

            menu.VerticalAlignment = VerticalAlignment.Top;
            menu.HorizontalAlignment = HorizontalAlignment.Left;
            
            // 'File' menu
            //
            // Create a menu item 'File'
            XamMenuItem menuItemFile = new XamMenuItem();
            menuItemFile.Header = "File";

            // Create a child menu item 'New'
            XamMenuItem menuItemFileNew = new XamMenuItem();
            menuItemFileNew.Header = "New";          

            // Add the created child menu item to the menu item 'File' collection
            menuItemFile.Items.Add(menuItemFileNew);

            // Create a child menu item 'Open'
            XamMenuItem menuItemFileOpen = new XamMenuItem();
            menuItemFileOpen.Header = "Open";

            // Create and add an icon to the submenu item
            Image openIcon = new Image();
            BitmapImage bmi = new BitmapImage(new Uri(imageResourcePathOpen, UriKind.Relative));

            openIcon.Source = bmi;
            menuItemFileOpen.Icon = openIcon;
            menuItemFile.Items.Add(menuItemFileOpen);

            XamMenuItem menuItemFileSave = new XamMenuItem();
            menuItemFileSave.Header = "Save";
            
            Image saveIcon = new Image();
            BitmapImage bmiSave = new BitmapImage(new Uri(imageResourcePathSave, UriKind.Relative));

            saveIcon.Source = bmiSave;
            menuItemFileSave.Icon = saveIcon;

            menuItemFile.Items.Add(menuItemFileSave);

            // Add a separator element between the menu items
            XamMenuSeparator separator = new XamMenuSeparator();
            menuItemFile.Items.Add(separator);

            XamMenuItem menuItemFileExit = new XamMenuItem();
            menuItemFileExit.Header = "Exit";
            menuItemFile.Items.Add(menuItemFileExit);

            menu.Items.Add(menuItemFile);

            // Edit menu 
            XamMenuItem menuItemEdit = new XamMenuItem();
            menuItemEdit.Header = "Edit";

            XamMenuItem menuItemEditCut = new XamMenuItem();
            menuItemEditCut.Header = "Cut";
            menuItemEdit.Items.Add(menuItemEditCut);

            XamMenuItem menuItemEditCopy = new XamMenuItem();
            menuItemEditCopy.Header = "Copy";
            menuItemEdit.Items.Add(menuItemEditCopy);

            XamMenuItem menuItemEditPaste = new XamMenuItem();
            menuItemEditPaste.Header = "Paste";
            menuItemEdit.Items.Add(menuItemEditPaste);

            menu.Items.Add(menuItemEdit);

            // TODO: Add more menu items in the XamMenu control

            // Add the created menu control to the grid container LayoutRoot
            LayoutRoot.Children.Add(menu);
            
            // Position the XamMenu in the second grid row
            Grid.SetRow(menu, 2);
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }
    }
}
